﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace Catering.View_Operaction
{
    public class Richang_Manage_Operaction
    {
        #region 承包商信息
        #region 住信息
        public Boolean InsertInfoToServer(string RowInfo)
        {
            Catering_Model.Contractor cmcc = new Catering_Model.Contractor();
            Catering_Rules.Contractor crcc = new Catering_Rules.Contractor();
            Boolean reset = false;
            if (RowInfo != null && RowInfo.Length > 0)
            {
                try
                {
                    string[] row = RowInfo.Split(new char[] { ',', ' ' });
                    cmcc.CName = row[0];
                    cmcc.LinkId = row[1];
                    cmcc.Tel = row[2];
                    cmcc.Address = row[3];
                    cmcc.State = row[4];
                    cmcc.Description = row[5];
                    cmcc.ContraType = "1";//-----------------------------------------------------------------------------
                    cmcc.ClassId = 0;
                    crcc.Add(cmcc);
                    reset = true;
                }
                catch
                {
                }

            }
            return reset;
        }
        public string show_Chengbaoshang(string GroupID, string ClassID)
        {
            DataSet ds = new Catering_Rules.Contractor().GetAllList();
            if (ds != null && ds.Tables.Count > 0)
            {
                return show_Chengbaoshang(ds.Tables[0]);
            }
            else
            {
                return string.Empty;
            }
        }
        private string show_Chengbaoshang(DataTable dt)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr != null)
                    {
                        sb.Append("<tr>");
                        sb.Append("<td align=\"center\">" + dr["id"] + " </td>");
                        sb.Append("<td align=\"center\">" + dr["CName"] + "</td>");
                        sb.Append("<td align=\"center\">" + dr["LinkId"] + "</td>");
                        sb.Append("<td align=\"center\">" + dr["Tel"] + "</td>");
                        sb.Append("<td align=\"center\">" + dr["Address"] + "</td>");
                        sb.Append("<td align=\"center\">" + dr["State"] + "</td>");
                        sb.Append("<td align=\"center\">" + dr["Description"] + "</td>");
                        sb.Append("<td><a href=\"#\" onclick='but_Show_Info(" + dr["id"] + ")' ><img src=\"../../../Images/file.gif\" /></a> </td>");
                        sb.Append("<td><a href=\"#\" onclick=\"Del_Chengbaosheng_Info(" + dr["id"] + ")\"><img src=\"../../../Images/trash.gif\" /></a> </td>");

                        sb.Append(" </tr>");
                    }
                }
            }
            return sb.ToString();
        }
        #endregion
        #region 详细信息
        public string show_Chengbaoshang_Info(string str)
        {
            Catering_Rules.ContractorInfo crc = new Catering_Rules.ContractorInfo();
            DataSet ds = crc.GetList(str);
            if (ds != null && ds.Tables.Count > 0)
            {
                return show_Chengbaoshang_Info(ds.Tables[0]);
            }
            else
            {
                return string.Empty;
            }
        }
        private string show_Chengbaoshang_Info(DataTable dt)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr != null)
                    {
                        sb.Append("<tr id=\"row\"" + dr["id"] + " onclick=\"select_Info_Id(" + dr["id"] + ")\">");
                        sb.Append("<td> " + dr["id"] + "</td>");
                        sb.Append("<td >" + dr["CName"] + "</td>");
                        sb.Append("<td >" + dr["GroupID"] + "</td>");


                        sb.Append("<td >" + dr["CardNo"] + "</td>");
                        sb.Append("<td >" + dr["JobCard"] + "</td>");
                        string Effective = dr["Effective"] == null || dr["Effective"].ToString().Length < 1 ? "1" : dr["Effective"].ToString();
                        Catering_Model.ClassInfo cmci = new Catering_Rules.ClassInfo().GetModel(Convert.ToInt32(Effective));

                        Catering_Model.OperationArea oa = new Catering_Rules.OperationArea().GetModel(cmci.AreaID);
                        sb.Append("<td >" + cmci.CName + "</td>");
                        sb.Append("<td >" + oa.AreaName + "</td>");


                        sb.Append("<td >" + dr["temp1"] + "</td>");
                        sb.Append("<td >" + dr["temp1"] + "</td>");
                        sb.Append("<tr>");

                    }
                }
            }
            return sb.ToString();
        }
        //保存
        public string add_Chengbaoshang_Info(string RowInfos, string rowid, out string Infoid)
        {
            int id = 0;
            string str = "NO";
            if (RowInfos != null && RowInfos.Trim().Length > 0 && rowid != null)
            {
                string[] infos = RowInfos.Split(new char[] { ',', ' ' });
                Catering_Model.ContractorInfo cmci = new Catering_Model.ContractorInfo();
                Catering_Rules.ContractorInfo crci = new Catering_Rules.ContractorInfo();
                if (infos.Length > 0)
                {
                    try
                    {
                        id = crci.GetMaxId();
                        cmci.id = id;
                        cmci.CID = Convert.ToInt32(rowid);
                        cmci.CName = infos[0];
                        cmci.GroupID = infos[1];
                        cmci.CardNo = infos[2];
                        cmci.JobCard = infos[3];
                        //cmci.EffectiveArea = infos[4];---------------------------------
                        cmci.Tel = infos[5];
                        cmci.Effective = "";
                        //cmci.temp1 = infos[6];-------------------------------------
                        //cmci.temp2 = "";-------------------------------------
                        crci.Add(cmci);
                        str = "OK";
                    }
                    catch
                    {
                    }
                }
            }
            Infoid = id.ToString();
            return str;

        }
        public string Update_Chengbaoshang_Info(string RowInfos, string rowid)
        {
            int id = 0;
            string str = "NO";
            if (RowInfos != null && RowInfos.Trim().Length > 0 && rowid != null)
            {
                string[] infos = RowInfos.Split(new char[] { ',', ' ' });
                Catering_Model.ContractorInfo cmci = new Catering_Model.ContractorInfo();
                Catering_Rules.ContractorInfo crci = new Catering_Rules.ContractorInfo();
                if (infos.Length > 0)
                {
                    try
                    {
                        id = crci.GetMaxId();
                        cmci.id = Convert.ToInt32(rowid);

                        cmci.CName = infos[0];
                        cmci.GroupID = infos[1];
                        cmci.CardNo = infos[2];
                        cmci.JobCard = infos[3];
                        //cmci.EffectiveArea = infos[4];------------------------------------
                        cmci.Tel = infos[5];
                        cmci.Effective = "";
                        //cmci.temp1 = infos[6];-------------------------------
                        //cmci.temp2 = "";--------------------------
                        crci.Update(cmci);
                        str = "OK";
                    }
                    catch
                    {
                    }
                }
            }

            return str;

        }
        #endregion
        #endregion
        #region
        public string Seacher_Jiucan_List(string strGroupID, string strClassID, string strStatDate, string strStop)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            if (strGroupID != null && strClassID != null && strStatDate != null && strStop != null)
            {
                Catering_Rules.DynamicType crdt = new Catering_Rules.DynamicType();
                DataSet ds_type = crdt.GetAllList();
                Catering_Rules.Dynamics crd = new Catering_Rules.Dynamics();
                string strWhere = "GroupID=" + strGroupID + " and ClassID=" + strClassID + " and Dates between '" + strStatDate + "' and' " + strStop + "'";
                DataSet ds = crd.GetList(strWhere);

                if (ds != null && ds.Tables.Count > 0 && ds_type != null && ds_type.Tables.Count > 0)
                {
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0 && ds_type.Tables[0] != null && ds_type.Tables[0].Rows.Count > 0)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow dr in ds_type.Tables[0].Rows)
                        {
                            if (dr["id"] != null)
                            {
                                DataRow[] dr_s = ds.Tables[0].Select("EatTID=" + dr["id"]);
                                int Number = 0;
                                foreach (DataRow dr_Number in dr_s)
                                {
                                    Number = Number + Convert.ToInt32(dr_Number["Eat"]);
                                }
                                sb.Append("<tr> ");
                                sb.Append("<td>" + dr["id"] + "</td>");
                                sb.Append("<td>" + dr["Name"] + "</td>");
                                sb.Append("<td>" + Number + "</td>");
                                sb.Append("</tr>");
                            }
                        }

                    }
                }
            }
            return sb.ToString();
        }
        public Int32[] Seacher_renyuandongtai(string strGroupID, string strClassID, string strStatDate, string strStop)
        {
            Int32[] dys = new Int32[6];
            Catering_Rules.Dynamic crd = new Catering_Rules.Dynamic();
            string strWhere = "GroupID=" + strGroupID + " and ClassID=" + strClassID + " and [Date] between '" + strStatDate + "' and' " + strStop + "'";
            DataSet ds = crd.GetList(strWhere);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    dys[0] = Convert.ToInt32(dys[0] == null ? 0 : dys[0]) + Convert.ToInt32(dr["Number"]);
                    dys[1] = Convert.ToInt32(dys[1] == null ? 0 : dys[1]) + Convert.ToInt32(dr["Catering"]);
                    dys[2] = Convert.ToInt32(dys[2] == null ? 0 : dys[2]) + Convert.ToInt32(dr["HPersons"]);
                    dys[3] = Convert.ToInt32(dys[3] == null ? 0 : dys[3]) + Convert.ToInt32(dr["QC"]);
                    dys[4] = Convert.ToInt32(dys[4] == null ? 0 : dys[4]) + Convert.ToInt32(dr["persons"]);

                }
            }
            return dys;

        }
        public DataTable Seacher_Jiucan(string strGroupID, string strClassID, string strStatDate, string strStop, int infoType)
        {
            Catering_Rules.Dynamics crd = new Catering_Rules.Dynamics();
            string strWhere = "AND Dates between '" + strStatDate + "' and' " + strStop + "' ";
            if (infoType == 2 && !string.IsNullOrEmpty(strGroupID) && !string.IsNullOrEmpty(strClassID))
            {
                strWhere = "AND GroupID=" + strGroupID + " and ClassID=" + strClassID + " and Dates between '" + strStatDate + "' and' " + strStop + "' ";
            }
            else if (infoType == 1 && !string.IsNullOrEmpty(strGroupID))
            {
                strWhere = "AND GroupID=" + strGroupID + " and Dates between '" + strStatDate + "' and' " + strStop + "' ";
            }
            DataTable dt_dys = crd.GetListGroupByDanWei(strWhere, "temp1").Tables[0];
            return dt_dys;
        }
        #endregion

    }
}